package com.my.mybatis.service.impl;

import com.my.mybatis.classDao.UserDaoClass;
import com.my.mybatis.entity.User;
import com.my.mybatis.generator.dao.UserMapper;
import com.my.mybatis.generator.dao.UserUserMapper;
import com.my.mybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Author:wangbin.
 * @Description.
 * @Date:Created in 17:20 2017/9/7.
 * @Modified By:
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    UserDaoClass userDaoClass;

    @Autowired
    UserMapper userMapper;

    @Autowired
    UserUserMapper userUserMapper;

    @Override
    public User getUser(int id) {
        User returnUser = userDaoClass.getUser(id);
        return returnUser;
    }

    @Override
    public void addUser(User user) {

    }

    @Override
    public Integer updateUser(User user) {
        return null;
    }

    @Override
    public Integer deleteUser(int UserId) {
        return null;
    }

    @Transactional(rollbackFor = {RuntimeException.class})
    public void insertUserTranstion() {
        com.my.mybatis.generator.entity.User user = new com.my.mybatis.generator.entity.User();
        user.setUsername("测试事务");
        user.setPassword("8520");
        userMapper.insert(user);

        userUserMapper.selectByPrimaryKey(2);
    }
}
